package com.lnsoft.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;


public class PropUtil {
	private static Properties prop = new Properties();
	
	static{		
		InputStream propIS = PropUtil.class.getResourceAsStream("/config.properties");
		try {
			prop.load(propIS);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static String getProperty(String key){
		try {
			return new String(prop.getProperty(key).getBytes("iso8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 以[KGSB=17,23]样式,返回数据列表
	 * @param key
	 * @return
	 */
	public static List<String> getProperty2List(String key){
		return Arrays.asList(PropUtil.getProperty(key).split(","));
	}
	/**
	 * GDLX=1:ZG,2:DS样式，将数据以map方式返回
	 * @param key
	 * @return
	 */
	public static Map<String,String> getProperty2Map(String key){
		List<String> list = PropUtil.getProperty2List(key);
		Map<String,String> map = new HashMap<String,String>();
		for(String str:list){
			String []kv = str.split(":");
			map.put(kv[0],kv[1]);
		}
		return map;
	}
}
